#include <iostream>
#include <vector>
#include <cmath>
#include <fstream>
#include <string>
#include <iomanip>  
#include <cblas.h>
#include <lapacke.h>
#include "Spline.hpp"  
#include "UniqueSpline.hpp" 

// 示例函数 F(x)
double F(double x) {
    return 1 / (1 + x * x);
}

void C_1(const std::vector<double>& x_points, const std::vector<double>& y_points){
    // 创建 BSpline 对象，使用 "complete" 边界条件
    double y_1a = 10 / std::pow(26, 2);  
    double y_1b = -10 / std::pow(26, 2); 
    BSpline p(x_points, y_points, 3, "complete", y_1a, y_1b);

    std::cout << "Interpolation Errors for BSpline" << ":\n";
    double x_values[] = {-3.5, -3, -0.5, 0, 0.5, 3, 3.5};
    for (double x : x_values) {
        double splineValue = p.getSplineValue(x);
        double error = fabs(splineValue - F(x));
        std::cout << "ES(" << x << ") = " << error << std::endl;
    }
}

void C_2(const std::vector<double>& x_points, const std::vector<double>& y_points){
    // 创建 SpecialBSpline 对象，使用 "complete" 边界条件
    double y_1a = 1/(1+5*5);  
    double y_1b = 1/(1+5*5); 
    SpecialBSpline spline(x_points, y_points, y_1a, y_1b);

    std::cout << "Interpolation Errors for SpecialSpline" << ":\n";
    double x_values[] = {-3.5, -3, -0.5, 0, 0.5, 3, 3.5};
    for (double x : x_values) {
        double splineValue = spline.getSplineValue(x);
        double error = fabs(splineValue - F(x));
        std::cout << "ES(" << x << ") = " << error << std::endl;
    }
}

int main() {
    // 生成插值数据点
    std::vector<double> x_points;
    std::vector<double> y_points;

    for (int i = 0; i <= 10; ++i) {
        double x = -5 + i * (10.0 / 10); 
        x_points.push_back(x);
        y_points.push_back(F(x));  
    }
    C_1(x_points, y_points);

    std::vector<double> x2_points;
    std::vector<double> y2_points;
    for (int i = 1; i <= 10; ++i) {
        double x = i-5.5; 
        x2_points.push_back(x);
        y2_points.push_back(F(x));  
    }

    C_2(x2_points, y2_points);

    return 0;
}